<?php
	$u_consultant = isset($_GET['consultant'])?$_GET['consultant']:'';
	$current_uid = $this->session->userdata('user_id');
?>
<?php $this->load->view('header');?>

<div class="page-container">
	<?php $this->load->view('sidebar');?>
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<?php $this->load->view('sale/_sub_nav');?>
			<div class="row">
				<div class="col-md-12">
					<?php if(isset($message)&&!empty($message)):?>
	                <?php $this->load->view('alert_message',$message);?>
	                <?php endif;?> 
					<div class="table-toolbar">
						<div class="form-inline">
					 		<label>
								查看范围
								<select name="" id="clue_range_select" class="form-control">
									<option value="<?php echo site_url('/sale/receptions');?>">所有线索</option>
									<?php foreach ($consultants as $consultant) :?>
				                        <option value="<?php echo site_url('/sale/receptions?consultant='.$consultant['id']);?>" <?php echo $u_consultant==$consultant['id']?'selected="selected"':'';?>>
				                            <?php echo $consultant['nickname']; ?>的线索
				                        </option>
				                    <?php endforeach; ?>
								</select>
							</label> 
							<div class="pull-right">
								<?php if(has_permission('sale/clues','clue_add')):?>
								<a href="<?php echo site_url('/sale/clues_create');?>" class="btn blue" >
								 <i class="fa fa-plus"></i> 新建 
								</a> 
								<?php endif;?>
								<button id="clue_search_btn" class="btn yellow">
								 <i class="fa fa-search"></i> 搜索 
								</button> 
								<?php if(has_permission('sale/clues','clue_import')):?>
								<button id="clue_import_btn" class="btn dark" data-toggle="modal" data-target="#import_modal">
								 <i class="fa fa-download"></i> 导入 
								</button> 
<!--								<button id="clue_export_btn" class="btn dark" data-toggle="modal" data-target="#dist_modal">-->
<!--								 <i class="fa fa-upload"></i> 导出-->
<!--								</button>-->
								<?php endif;?>
								<?php if(has_permission('sale/clues','clue_dist')):?>
								<button id="clue_dist_btn" class="btn red" data-toggle="modal" data-target="#dist_modal">
									<i class="fa fa-download"></i> 分配
								</button>
								<?php endif;?>
							</div>
						</div>
					</div>
						
						<div class="row" style="display:none;" id="clue_search_well">
							<div class="col-md-12 well">
								<form id="clue_search_form">
									<table class="table">
										<tr><td colspan="6"><div class="well shallow-well">
											<span class="filter-link-list">
												按首字母来查询:
												<?php for($i=ord('a');$i<ord('z');$i++):?>
													 <a href="javascript:void(0);" class="letter_selector"><?php echo strtoupper(chr($i));?></a>
												<?php endfor;?>		
											</span>
											<input type="hidden" name="letter" value="" id="letter_hidden">
										</div></td>			
										</tr>
										<tr>
											<td><label><?php echo lang('clue_student_name');?></label></td>
											<td><input type="text" name="student_name" class="form-control"></td>
											<td><label><?php echo lang('clue_student_no');?></label></td>
											<td><input type="text" name="student_no" class="form-control"></td>
											<td><label><?php echo lang('clue_phone');?></label></td>
											<td><input type="text" name="phone" class="form-control"></td>						
										</tr>
										<tr>
											<td><label class="control-label"><?php echo lang('clue_last_contact_date');?></label></td>
											<td><div class="input-group input-large date-picker input-daterange" data-date="10/11/2012" data-date-format="mm/dd/yyyy">
												<input type="text" class="form-control" name="from">
												<span class="input-group-addon">
													 to
												</span>
												<input type="text" class="form-control" name="to">
											</div></td>
											<td><label class="control-label"><?php echo lang('clue_trade_wish');?></label></td>
											<td>
												<select class="form-control" name="trade_wish">
													<option value=""></option>
													 <?php foreach(config_item('comm.trade_wish') as $key=>$value):?>
						                                <option value="<?php echo $key;?>"><?php echo $value;?></option>
						                            <?php endforeach;?>
												</select>
											</td>
											<td><label><?php echo lang('clue_consultant');?></label></td>
											<td>
												<select class="form-control" name="consultant">
													<option value=""></option>
						                                <?php if (isset($consultants) && is_array($consultants) && count($consultants)) :?>
						                                    <?php foreach ($consultants as $consultant) :?>
						                                         <option value="<?php echo $consultant['id']; ?>">
						                                            <?php echo $consultant['nickname']; ?>
						                                        </option>
						                                    <?php endforeach; ?>
						                                <?php endif;?>
 -->												</select>
											</td>					
										</tr>
										<tr>
											<td><label class="control-label"><?php echo lang('clue_school');?></label></td>
											<td><input type="text" class="form-control"></td>					
											<td><label class="control-label"><?php echo lang('clue_grade');?></label></td>
											<td>
												<select class="form-control" name="grade">
													<option value=""></option>
													 <?php foreach(config_item('comm.grade') as $key=>$value):?>
						                                <option value="<?php echo $key;?>"><?php echo $value;?></option>
						                            <?php endforeach;?>
												</select>
											</td>
											<td>
												<label class="control-label"><?php echo lang('clue_source');?></label>	
											</td>
											<td>
												<select class="form-control" name="clue_source">
													<option value=""></option>
													 <?php foreach(config_item('comm.clue_source') as $key=>$value):?>
						                                <option value="<?php echo $key;?>"><?php echo $value;?></option>
						                            <?php endforeach;?>
												</select>
											</td>
										</tr>
										<tr>
											<td><label class="control-label"><?php echo lang('clue_next_track_date');?></label></td>
											<td>
							                       <input class="form-control form-control-inline date-picker" name="next_contact_date" size="16" type="text" value=""/>
											</td>					
											<td><label class="control-label"><?php echo lang('from_big');?></label></td>
											<td>
												<select class="form-control" name="from_big">
													<option value=""></option>
													 <?php foreach(config_item('comm.from_big') as $key=>$value):?>
						                                <option value="<?php echo $key;?>"><?php echo $value;?></option>
						                            <?php endforeach;?>
												</select>
											</td>
											<td>
												<label class="control-label"><?php echo lang('clue_stat');?></label>	
											</td>
											<td>
												<select class="form-control" name="clue_stat">
													 <option value=""></option>
													 <?php foreach(config_item('comm.clue_status') as $key=>$value):?>
						                                <option value="<?php echo $key;?>"><?php echo $value;?></option>
						                            <?php endforeach;?>
												</select>
											</td>
										</tr>
										<tr>
											<td>
												<label class="control-label"><?php echo lang('clue_track_nums');?></label>	
											</td>
											<td>
												<select class="form-control" name="contact_times">
													  <option value=""></option>
													  <?php for($i=0;$i<6;$i++):?>
													  	 <option value="<?php echo $i;?>"><?php echo $i;?>次</option>
													  <?php endfor;?>
													  <option value="6">6-10次</option>
													  <option value="10">大于10次</option>
												</select>
											</td>
											<td>
											</td>
											<td>
											</td>
											<td>
											</td>
											<td>
											</td>
										</tr>
										</form>
										<tr>
											<td colspan="5"></td>
											<td><button class="btn btn-success" type="button" id="search_submit_btn" >查询</button> <button class="btn btn-default" type="submit">重置</button></td>
										</tr>

									</table>
							</div>
						</div>


						<table class="table table-hover" id="clues_table">
							<thead>
								<tr>
									<th class="table-checkbox"><input type="checkbox" class="group-checkable" data-set="#clues_table .checkboxes"></th>
									<th><?php echo lang('clue_student_name');?></th>
									<th><?php echo lang('clue_student_no');?></th>
									<th><?php echo lang('clue_parent_name1');?></th>
									<th><?php echo lang('clue_trade_wish');?></th>
									<th><?php echo lang('clue_tel');?></th>
									<th><?php echo lang('clue_school');?></th>
									<th><?php echo lang('clue_grade');?></th>
									<th><?php echo lang('clue_track_nums');?></th>
									<th><?php echo lang('clue_consultant');?></th>
									<th><?php echo lang('clue_last_contact_result');?></th>
									<th><?php echo lang('clue_last_contact_date');?></th>
									<th><?php echo lang('clue_next_contact_date');?></th>
									<th><?php echo lang('clue_stat');?></th>
									<th><?php echo lang('actions');?></th>
								</tr>
							</thead>
							
						</table>

						<div class="table-toolbar">
								<?php if(has_permission('sale/clues','dist')):?>
								<button id="clue_dist_btn" class="btn yellow" data-toggle="modal" data-target="#dist_modal">
								 <i class="fa fa-plus"></i> 转移 
								</button>
								<?php endif;?>
								<?php if(has_permission('sale/clues','delete')):?>
								<a id="clue_delete_btn" class="btn red" >
								 <i class="fa fa-trash-o"></i> 删除 
								</a> 
								<?php endif;?>
								<?php if(has_permission('sale/clues','operate')):?>
								<div class="btn-group">
									<button class="btn dropdown-toggle" data-toggle="dropdown">更多操作 <i class="fa fa-angle-down"></i>
									</button>
									<ul class="dropdown-menu pull-right">
										<li>
											<a href="#">
												 发送邮件
											</a>
										</li>
										<li>
											<a href="#">
												 发短信
											</a>
										</li>
									</ul>
								</div>   
								<?php endif;?>

						</div>
				</div>
			</div>
		</div>
	</div>
		
	
	<div class="modal fade" id="dist_modal" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">分配/转移</h4>
				</div>
				<div class="modal-body">
					<form action="" method="POST" class="form-horizontal" role="form" id="clue_dist_from">
						<input type="hidden" name="clue_ids" id="clue_ids" />												
						<div class="form-group">
							<label class="control-label col-md-4">转移拥有关系</label>
							<div class="col-sm-6">
								<select name="" id="new_owner" class="form-control" required="required">
										<?php foreach ($consultants as $consultant) :?>
					                        <option value="<?php echo $consultant['id']; ?>">
					                            <?php echo $consultant['nickname']; ?>的线索
					                        </option>
					                    <?php endforeach; ?>
								</select>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="dist_submit_btn">分配/转移</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->

	<div class="modal fade" id="track_modal" role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title"><?php echo lang('clue_new_track');?></h4>
				</div>
				<div class="modal-body">
					<?php echo form_open('', array('class'=>'form-horizontal','role'=>'form','id'=>'track_form')); ?>
<!-- 				        <h3 class="form-section"><?php echo lang('clue_detail'); ?></h3>
 -->		            <div class="form-group">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_student_name_no'); ?><span class="required">*</span></label>
		                    <div class="col-md-9">
		                        <input type="text" name="" id="student_name" readonly class="form-control" value=" " />
		                        <input type="hidden" name="student_id" id="student_id" value="">
		                        <span class="help-block"></span>
		                    </div>
		                </div>

 						<div class="form-group<?php echo form_error('title') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_track_title'); ?></label>
		                    <div class="col-md-9">
		                        <input type="text" name="title" id="title" class="form-control" value="<?php echo set_value('role_name', isset($role) ? $role->role_name : ''); ?>" />
		                        <span class="help-block"><?php echo form_error('title'); ?></span>
		                    </div>
		                </div>

		                <div class="form-group<?php echo form_error('track_wish') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_trade_wish'); ?><span class="required">*</span></label>
		                    <div class="col-md-5">
		                        <select name="track_wish" id="track_wish" class="form-control" >
		                            <?php foreach(config_item('comm.trade_wish') as $key=>$value):?>
		                                <option value="<?php echo $key;?>" <?php echo set_select('track_wish', $key); ?>><?php echo $value;?></option>
		                            <?php endforeach;?>
		                        </select>
		                        <span class="help-block"><?php echo form_error('track_wish'); ?></span>
		                    </div>
		                </div>

		                <div class="form-group<?php echo form_error('track_result') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_track_result'); ?><span class="required">*</span></label>
		                    <div class="col-md-5">
		                        <select name="track_result" id="track_result" class="form-control" >
		                            <?php foreach(config_item('comm.track_result') as $key=>$value):?>
		                                <option value="<?php echo $key;?>" <?php echo set_select('track_result', $key); ?>><?php echo $value;?></option>
		                            <?php endforeach;?>
		                        </select>
		                        <span class="help-block"><?php echo form_error('track_result'); ?></span>
		                    </div>
		                </div>


		                <div class="form-group<?php echo form_error('track_date') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_track_date'); ?><span class="required">*</span></label>
		                    <div class="col-md-5">
		                    	<div class="input-group date date-picker">
			                        <input type="text" name="track_date" id="track_datee" class="form-control" value="<?php echo set_value('role_name', isset($role) ? $role->role_name : ''); ?>" />
			                        <span class="input-group-btn">
										<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
									</span>
								</div>
		                        <span class="help-block"><?php echo form_error('track_date'); ?></span>
		                    </div>
		                </div>

		                <div class="form-group<?php echo form_error('next_track_date') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_next_track_date'); ?></label>
		                    <div class="col-md-5">
		                    	<div class="input-group date date-picker">
			                        <input type="text" name="next_track_date" id="track_next_date" class="form-control" value="<?php echo set_value('next_track_date', isset($role) ? $role->role_name : ''); ?>" />
			                        <span class="input-group-btn">
										<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
									</span>
								</div>
		                        <span class="help-block"><?php echo form_error('next_track_date'); ?></span>
		                    </div>
		                </div>

		                <div class="form-group<?php echo form_error('content') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_track_content'); ?></label>
		                    <div class="col-md-5">
		                        <textarea name="content" class="form-control"></textarea>
		                        <span class="help-block"><?php echo form_error('content'); ?></span>
		                    </div>
		                </div>				     			

		                 <div class="form-group<?php echo form_error('user_id') ? ' error' : ''; ?>">
		                    <label class="control-label col-md-3" ><?php echo lang('clue_consultant'); ?><span class="required">*</span></label>
		                    <div class="col-md-5">
		                        <select class="form-control" name="consultant" id="consultant">
		                                <?php if (isset($consultants) && is_array($consultants) && count($consultants)) :?>
		                                    <?php foreach ($consultants as $consultant) :?>
		                                         <option value="<?php echo $consultant['id']; ?>">
		                                            <?php echo $consultant['nickname']; ?>
		                                        </option>
		                                    <?php endforeach; ?>
		                                <?php else:?>
		                                    <option value="0">无</option>
		                                <?php endif;?>
<!-- 		                                <option value="<?php echo $current_uid; ?>"?><?php echo $current_user->display_name;?></option>
 -->		                        </select>
		                        <span class="help-block"><?php echo form_error('user_id'); ?></span>
		                    </div>
		                </div>				     			
	
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo lang('action_cancel');?></button>
					<button type="submit" class="btn btn-primary" name="save"><?php echo lang('action_save');?></button>
				</div>

				<?php echo form_close();?>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->

	<div class="modal fade" id="import_modal">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">导入线索</h4>
				</div>
				<div class="modal-body">
					<form id="upload-form" action="" method="POST" enctype="multipart/form-data" id="upload-form" class="form-horizontal">
						<div class="form-group" id="file-group">
							<div class="col-md-12">
								<label for="" class="col-md-3 control-label">上传文件<span class="required">*</span></label>
								<div class="fileinput fileinput-new col-md-7" data-provides="fileinput">
									<input type="hidden" name="name" id="name" value=""/>
								<span class="btn default btn-file">
									<span class="fileinput-new">
										 选择文件
									</span>
									<span class="fileinput-exists">
										 更换文件
									</span>
									<input type="file" name="files" id="fileupload"  accept=".xls,.csv,.xlsx">
								</span>
									<span class="fileinput-filename"></span>
									&nbsp;
									<a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">
									</a>
									<span class="fileupload-process"></span>
								</div>
							</div>
						</div>
					</form>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id='import_submit_btn'>开始导入</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->

	<script id="template-upload" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-upload fade">
                <td>
                    <span class="preview"></span>
                </td>
                <td>
                    <p class="name">{%=file.name%}</p>
                    {% if (file.error) { %}
                        <div><span class="label label-danger">Error</span> {%=file.error%}</div>
                    {% } %}
                </td>
                <td>
                    <p class="size">{%=o.formatFileSize(file.size)%}</p>
                    {% if (!o.files.error) { %}
                        <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                        <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                        </div>
                    {% } %}
                </td>
                <td>
                    {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                        <button class="btn blue start btn-sm">
                            <i class="fa fa-upload"></i>
                            <span>Start</span>
                        </button>
                    {% } %}
                    {% if (!i) { %}
                        <button class="btn red cancel btn-sm">
                            <i class="fa fa-ban"></i>
                            <span>Cancel</span>
                        </button>
                    {% } %}
                </td>
            </tr>
        {% } %}
    </script>

	<!-- The template to display files available for download -->
	<script id="template-download" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-download fade">
                <td>
                    <span class="preview">
                        {% if (file.thumbnailUrl) { %}
                            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
                        {% } %}
                    </span>
                </td>
                <td>
                    <p class="name">
                        {% if (file.url) { %}
                            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                        {% } else { %}
                            <span>{%=file.name%}</span>
                        {% } %}
                    </p>
                    {% if (file.error) { %}
                        <div><span class="label label-danger">Error</span> {%=file.error%}</div>
                    {% } %}
                </td>
                <td>
                    <span class="size">{%=o.formatFileSize(file.size)%}</span>
                </td>
                <td>
                    {% if (file.deleteUrl) { %}
                        <button class="btn red delete btn-sm" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                            <i class="fa fa-trash-o"></i>
                            <span>Delete</span>
                        </button>
                        <input type="checkbox" name="delete" value="1" class="toggle">
                    {% } else { %}
                        <button class="btn yellow cancel btn-sm">
                            <i class="fa fa-ban"></i>
                            <span>Cancel</span>
                        </button>
                    {% } %}
                </td>
            </tr>
        {% } %}
    </script>
</div>

<?php $this->load->view('footer');?>

<!-- Jquery Validate -->
<script type="text/javascript" src="assets/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-validation/dist/additional-methods.min.js"></script>
<!-- Jquery Validate -->
<!-- Jquery Form -->
<script type="text/javascript" src="assets/plugins/jquery.form.js"></script>

<link href="assets/plugins/jquery-file-upload/blueimp-gallery/blueimp-gallery.min.css" rel="stylesheet"/>
<link href="assets/plugins/jquery-file-upload/css/jquery.fileupload.css" rel="stylesheet"/>
<link href="assets/plugins/jquery-file-upload/css/jquery.fileupload-ui.css" rel="stylesheet"/>

	<script src="assets/plugins/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script>
	<!-- The Templates plugin is included to render the upload/download listings -->
	<script src="assets/plugins/jquery-file-upload/js/vendor/tmpl.min.js"></script>
	<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
	<script src="assets/plugins/jquery-file-upload/js/vendor/load-image.min.js"></script>
	<!-- The Canvas to Blob plugin is included for image resizing functionality -->
	<script src="assets/plugins/jquery-file-upload/js/vendor/canvas-to-blob.min.js"></script>

	<link rel="stylesheet" type="text/css" href="assets/plugins/bootstrap-fileinput/bootstrap-fileinput.css"/>
	<script type="text/javascript" src="assets/plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>


	<script src="assets/plugins/jquery-file-upload/blueimp-gallery/jquery.blueimp-gallery.min.js"></script>
	<script src="assets/plugins/jquery-file-upload/js/jquery.iframe-transport.js"></script>
	<!-- The basic File Upload plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload.js"></script>
	<!-- The File Upload processing plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-process.js"></script>
	<!-- The File Upload image preview & resize plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-image.js"></script>
	<!-- The File Upload audio preview plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-audio.js"></script>
	<!-- The File Upload video preview plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-video.js"></script>
	<!-- The File Upload validation plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-validate.js"></script>
	<!-- The File Upload user interface plugin -->
	<script src="assets/plugins/jquery-file-upload/js/jquery.fileupload-ui.js"></script>



	<script type="text/javascript" src="assets/scripts/custom/clue.js"></script>

<script>
jQuery(document).ready(function() {    
   App.init(); // initlayout and core plugins
   Clue.init();
});
</script>

</body>
<!-- END BODY -->
</html>
